﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Collections;

namespace translateDelegateToEvent
{
    class Program
    {
        static void Main(string[] args)
        {
            StreamReader objReader = new StreamReader(@"C:\Users\RCYang\Desktop\delegates.txt");
            ArrayList lines = new ArrayList();
            string sLine = "";
            while (sLine != null)
            {
                sLine = objReader.ReadLine();
                if (sLine != null)
                {
                    sLine = sLine.Trim();
                    int leftParIndex = sLine.IndexOf('(');
                    string name = sLine.Substring(0, leftParIndex);
                    name = name.Replace("public delegate void ", "");
                    sLine = "\t\tpublic event " + name + " " + name.Replace("Handler", "Event;");
                    lines.Add(sLine);
                }
            }
            objReader.Close();
            //将文件导出到txt
            FileStream fs = new FileStream(@"C:\Users\RCYang\Desktop\delegates2events.txt", FileMode.Create);
            StreamWriter sw = new StreamWriter(fs);
            foreach (string a in lines)
            {
                sw.WriteLine(a);
            }
            sw.Flush();
            sw.Close();
            fs.Close();
        }
    }
}
